import React, { useEffect } from "react";

export default function FED4() {
    useEffect(() => {
        let onWatch = (obj, setBind, getLogger) => {
            let handler = {
                get(target, property, receiver) {
                    getLogger(target, property);
                    return Reflect.get(target, property, receiver);
                },
                set(target, property, value, receiver) {
                    setBind(value, property);
                    return Reflect.set(target, property, value, receiver);
                },
            };
            return new Proxy(obj, handler);
        };
        let obj = { a: 1 };
        let p = onWatch(
            obj,
            (v, property) => {
                console.log(`监听到${property}属性值发生改变,改变为${v}`);
            },
            (target, property) => {
                console.log(`${property}-${target[property]}`);
            }
        );
        p.a = 2;
        console.log(p.a)
    }, []);
    return <div>proxy代理-实现数据响应式</div>;
}
